# 之前讲的锁都是只允许一个线程或者进程进入.
# 信号量允许多个线程或者进程同时进入
from threading import Thread
from threading import current_thread
from threading import Semaphore
import time
import random
sm = Semaphore(4)
# lock= Lock()
def go_public_wc():
    sm.acquire()
    print(f'{current_thread().name}正在厕所')
    time.sleep(random.randint(1, 3))
    sm.release()


if __name__ == '__main__':

    for i in range(20):
        t = Thread(target=go_public_wc)
        t.start()

    # print('主')